<?php
class Communication_Model_Deliveryemail extends Zen_List {
	public function __construct() {
		$this->table = new Communication_Model_Deliveryemail ();
	}
	
	public function beforeCreate($params) {
		$params ['create_date'] = date ( 'Y-m-d H:i:s' );
		return ($params);
	}
	
	public function afterCreate($id, $params) {
		$mail = new Communication_Model_Email ();
		$cnf = Zend_Registry::get ( 'cnf' );
		$roles = array ();
		foreach ( $params ['roles'] as $role ) {
			$roles [] = $role;
		}
		$in = implode ( ',', $roles );
		$users = new User_Model_Userslist ();
		$users->setLimit ( 0 );
		$us = $users->getList ( "`role_id` in(" . $in . ")" );
		foreach ( $us as $user ) {
			
			$message = array ("text" => $params ['text'], "subject" => $params ['subject'], "from" => "noreply@" . $cnf->domen, "to" => $user ['email'] );
			$mail->create ( $message );
		}
		$mail->send_messages ();
	
	}

}

?>